// @flow
import React from 'react'
import { Modal, Button, Form, Popconfirm } from 'antd'
type Props = {
  ignoreMeg: Function,
  order: Function,
  data: Object,
  gotoDetail: Function,
  state: Object,
  index: Object
}

type States = {
  loading: boolean,
  visible: boolean
}
class WarningModel extends React.Component {
  props: Props
  state: States
  constructor (props: Props) {
    super(props)
    this.state = {
      loading: false,
      visible: false
    }
  }
  showModal = () => {
    this.setState({
      visible: true
    })
  }
  handleOk = () => {
    this.setState({ loading: true })
    setTimeout(() => {
      this.setState({ loading: false, visible: false })
    }, 1000)
  }
  handleCancel = () => {
    this.setState({ visible: false })
  }
  ignore = () => {
    this.setState({
      visible: false
    })
    const { data, index } = this.props
    this.props.ignoreMeg(data, index)
  }
  order = () => {
    this.setState({
      visible: false
    })
    const { data, index } = this.props
    this.props.order(data, index)
  }
  // detail = () => {
  //   this.setState({
  //     visible: false
  //   })
  //   this.props.gotoDetail()
  // }
  render () {
    const { data } = this.props
    return (
      <div>
        <Button type='primary' size='small' onClick={this.showModal}>
          详情
        </Button>
        <Modal
          visible={this.state.visible}
          title='预警消息详情'
          onOk={this.handleOk}
          onCancel={this.handleCancel}
          footer={[
            // <Button key='detail' size='small' onClick={this.detail}>查看详情</Button>,
            <Button key='list' size='small' onClick={this.order}>生成工单</Button>,
            // <Button key='meg' size='small'>发送消息</Button>,
            <Button key='ignore' size='small'>
              <Popconfirm title='确认忽略吗?' onConfirm={this.ignore}>
                 忽略
              </Popconfirm>
            </Button>
          ]}
        >
          <h3>设备:&nbsp;&nbsp;{ data.deviceNo }</h3>
          <h3>时间:&nbsp;&nbsp;{ data.waringTime }</h3>
          <h3>描述:&nbsp;&nbsp;{ data.message }</h3>
        </Modal>
      </div>
    )
  }
}

export default Form.create()(WarningModel)
